package com.qf;

import java.util.ArrayList;
import java.util.Iterator;

public class IteratorDemo {

    public static void main(String[] args) {

        ArrayList<String> list = new ArrayList<>();
        list.add("hello");
        list.add("word");
        list.add("nice ");
        list.add("to");

        Iterator<String> iterator = list.iterator();
        System.out.println(iterator);

        while (iterator.hasNext()) {
            String s = iterator.next();
            System.out.println(s);
        }


        for (String s : list) {
            System.out.println(s);
        }

        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }
        list.forEach((e)-> System.out.println(e));

    }
}
